<?php
$tel = "<table>
                <tr>
                    <td>Telefone adicionado</td>
                </tr>
            </table>";
if ($_GET['ExibirClienteID'] != null || $_GET['ExibirID'] != "") {
    continuar($_GET['ExibirClienteID']);
} else if ($_POST['ExibirClienteID'] != null || $_POST['ExibirClienteID'] != "") {
    continuar($_POST['ExibirClienteID']);
} else {
    ?>
    <h1>Não há nada para exibir</h1>
    <?php
}

function continuar($id) {
    include_once '../../SQL/connector.php';
    $con = new connector();
    $query = "SELECT 
                    p.idPessoa, 
                    p.nome, 
                    p.cpf, 
                    p.data_nascimento,
                    p.identidade,
                    p.emissor_identidade,
                    p.estado_civil,
                    p.sexo
                FROM Pessoa AS p
                WHERE
                    p.idPessoa = " . $id . "
                LIMIT 1;";

    $result = $con->executaSql($query);
    while ($linha = mysql_fetch_row($result)) {
        ?>
        <form name="exibirCliente" >
            <table>
                <tr>
                    <td colspan="2" align="center" id="exibir_cli_response">

                    </td>
                </tr>
                <tr><td><label>ID do Cliente:&nbsp;&nbsp;</label></td>
                    <td>
                        <input type="text" disabled="disabled" maxlength="5" name="idCliente"
                               value="<?php echo $linha[0]; ?>"></input>
                    </td></tr>
                <tr><td><label>Nome:&nbsp;&nbsp;</label></td>
                    <td>
                        <input type="text" name="nome"
                               value="<?php echo $linha[1]; ?>"></input>
                    </td></tr>
                <tr><td><label>CPF:&nbsp;&nbsp;</label></td>
                    <td>
                        <input type="text" name="cpf"
                               value="<?php echo $linha[2]; ?>"></input>
                    </td></tr>
                <tr><td><label>Data de Nascimento:&nbsp;&nbsp;</label></td>
                    <td>
                        <?php
                                $data = explode("-", $linha[3]);
                                $dia = $data[2];
                                $mes = $data[1];
                                $ano = $data[0]; ?>
                        <select name="dia">
                            <option value="01" <?php if($dia == '01'){echo "selected=true";} ?> >01</option>
                            <option value="02" <?php if($dia == '02'){echo "selected=true";} ?> >02</option>
                            <option value="03" <?php if($dia == '03'){echo "selected=true";} ?> >03</option>
                            <option value="04" <?php if($dia == '04'){echo "selected=true";} ?> >04</option>
                            <option value="05" <?php if($dia == '05'){echo "selected=true";} ?> >05</option>
                            <option value="06" <?php if($dia == '06'){echo "selected=true";} ?> >06</option>
                            <option value="07" <?php if($dia == '07'){echo "selected=true";} ?> >07</option>
                            <option value="08" <?php if($dia == '08'){echo "selected=true";} ?> >08</option>
                            <option value="09" <?php if($dia == '09'){echo "selected=true";} ?> >09</option>
                            <option value="10" <?php if($dia == '10'){echo "selected=true";} ?> >10</option>
                            <option value="11" <?php if($dia == '11'){echo "selected=true";} ?> >11</option>
                            <option value="12" <?php if($dia == '12'){echo "selected=true";} ?> >12</option>
                            <option value="13" <?php if($dia == '13'){echo "selected=true";} ?> >13</option>
                            <option value="14" <?php if($dia == '14'){echo "selected=true";} ?> >14</option>
                            <option value="15" <?php if($dia == '15'){echo "selected=true";} ?> >15</option>
                            <option value="16" <?php if($dia == '16'){echo "selected=true";} ?> >16</option>
                            <option value="17" <?php if($dia == '17'){echo "selected=true";} ?> >17</option>
                            <option value="18" <?php if($dia == '18'){echo "selected=true";} ?> >18</option>
                            <option value="19" <?php if($dia == '19'){echo "selected=true";} ?> >19</option>
                            <option value="20" <?php if($dia == '20'){echo "selected=true";} ?> >20</option>
                            <option value="21" <?php if($dia == '21'){echo "selected=true";} ?> >21</option>
                            <option value="22" <?php if($dia == '22'){echo "selected=true";} ?> >22</option>
                            <option value="23" <?php if($dia == '23'){echo "selected=true";} ?> >23</option>
                            <option value="24" <?php if($dia == '24'){echo "selected=true";} ?> >24</option>
                            <option value="25" <?php if($dia == '25'){echo "selected=true";} ?> >25</option>
                            <option value="26" <?php if($dia == '26'){echo "selected=true";} ?> >26</option>
                            <option value="27" <?php if($dia == '27'){echo "selected=true";} ?> >27</option>
                            <option value="28" <?php if($dia == '28'){echo "selected=true";} ?> >28</option>
                            <option value="29" <?php if($dia == '29'){echo "selected=true";} ?> >29</option>
                            <option value="30" <?php if($dia == '30'){echo "selected=true";} ?> >30</option>
                            <option value="31" <?php if($dia == '31'){echo "selected=true";} ?> >31</option>
                        </select>
                        <select name="mes">
                            <option value="01" <?php if($mes == '01'){echo "selected=true";} ?> >Janeiro</option>
                            <option value="02" <?php if($mes == '02'){echo "selected=true";} ?> >Fevereiro</option>
                            <option value="03" <?php if($mes == '03'){echo "selected=true";} ?> >Março</option>
                            <option value="04" <?php if($mes == '04'){echo "selected=true";} ?> >Abril</option>
                            <option value="05" <?php if($mes == '05'){echo "selected=true";} ?> >Maio</option>
                            <option value="06" <?php if($mes == '06'){echo "selected=true";} ?> >Junho</option>
                            <option value="07" <?php if($mes == '07'){echo "selected=true";} ?> >Julho</option>
                            <option value="08" <?php if($mes == '08'){echo "selected=true";} ?> >Agosto</option>
                            <option value="09" <?php if($mes == '09'){echo "selected=true";} ?> >Setembro</option>
                            <option value="10" <?php if($mes == '10'){echo "selected=true";} ?> >Outubro</option>
                            <option value="11" <?php if($mes == '11'){echo "selected=true";} ?> >Novembro</option>
                            <option value="12" <?php if($mes == '12'){echo "selected=true";} ?> >Dezembro</option>
                        </select>
                        <select name="ano">
                            <option value="2015" <?php if($ano == '2015'){echo "selected=true";} ?> >2015</option>
                            <option value="2014" <?php if($ano == '2014'){echo "selected=true";} ?> >2014</option>
                            <option value="2013" <?php if($ano == '2013'){echo "selected=true";} ?> >2013</option>
                            <option value="2012" <?php if($ano == '2012'){echo "selected=true";} ?> >2012</option>
                            <option value="2011" <?php if($ano == '2011'){echo "selected=true";} ?> >2011</option>
                            <option value="2010" <?php if($ano == '2010'){echo "selected=true";} ?> >2010</option>
                            <option value="2009" <?php if($ano == '2009'){echo "selected=true";} ?> >2009</option>
                            <option value="2008" <?php if($ano == '2008'){echo "selected=true";} ?> >2008</option>
                            <option value="2007" <?php if($ano == '2007'){echo "selected=true";} ?> >2007</option>
                            <option value="2006" <?php if($ano == '2006'){echo "selected=true";} ?> >2006</option>
                            <option value="2005" <?php if($ano == '2005'){echo "selected=true";} ?> >2005</option>
                            <option value="2004" <?php if($ano == '2004'){echo "selected=true";} ?> >2004</option>
                            <option value="2003" <?php if($ano == '2003'){echo "selected=true";} ?> >2003</option>
                            <option value="2002" <?php if($ano == '2002'){echo "selected=true";} ?> >2002</option>
                            <option value="2001" <?php if($ano == '2001'){echo "selected=true";} ?> >2001</option>
                            <option value="2000" <?php if($ano == '2000'){echo "selected=true";} ?> >2000</option>
                            <option value="1999" <?php if($ano == '1999'){echo "selected=true";} ?> >1999</option>
                            <option value="1998" <?php if($ano == '1998'){echo "selected=true";} ?> >1998</option>
                            <option value="1997" <?php if($ano == '1997'){echo "selected=true";} ?> >1997</option>
                            <option value="1996" <?php if($ano == '1996'){echo "selected=true";} ?> >1996</option>
                            <option value="1995" <?php if($ano == '1995'){echo "selected=true";} ?> >1995</option>
                            <option value="1994" <?php if($ano == '1994'){echo "selected=true";} ?> >1994</option>
                            <option value="1993" <?php if($ano == '1993'){echo "selected=true";} ?> >1993</option>
                            <option value="1992" <?php if($ano == '1992'){echo "selected=true";} ?> >1992</option>
                            <option value="1991" <?php if($ano == '1991'){echo "selected=true";} ?> >1991</option>
                            <option value="1990" <?php if($ano == '1990'){echo "selected=true";} ?> >1990</option>
                            <option value="1989" <?php if($ano == '1989'){echo "selected=true";} ?> >1989</option>
                            <option value="1988" <?php if($ano == '1988'){echo "selected=true";} ?> >1988</option>
                            <option value="1987" <?php if($ano == '1987'){echo "selected=true";} ?> >1987</option>
                            <option value="1986" <?php if($ano == '1986'){echo "selected=true";} ?> >1986</option>
                            <option value="1985" <?php if($ano == '1985'){echo "selected=true";} ?> >1985</option>
                            <option value="1984" <?php if($ano == '1984'){echo "selected=true";} ?> >1984</option>
                            <option value="1983" <?php if($ano == '1983'){echo "selected=true";} ?> >1983</option>
                            <option value="1982" <?php if($ano == '1982'){echo "selected=true";} ?> >1982</option>
                            <option value="1981" <?php if($ano == '1981'){echo "selected=true";} ?> >1981</option>
                            <option value="1980" <?php if($ano == '1980'){echo "selected=true";} ?> >1980</option>
                            <option value="1979" <?php if($ano == '1979'){echo "selected=true";} ?> >1979</option>
                            <option value="1978" <?php if($ano == '1978'){echo "selected=true";} ?> >1978</option>
                            <option value="1977" <?php if($ano == '1977'){echo "selected=true";} ?> >1977</option>
                            <option value="1976" <?php if($ano == '1976'){echo "selected=true";} ?> >1976</option>
                            <option value="1975" <?php if($ano == '1975'){echo "selected=true";} ?> >1975</option>
                            <option value="1974" <?php if($ano == '1974'){echo "selected=true";} ?> >1974</option>
                            <option value="1973" <?php if($ano == '1973'){echo "selected=true";} ?> >1973</option>
                            <option value="1972" <?php if($ano == '1972'){echo "selected=true";} ?> >1972</option>
                            <option value="1971" <?php if($ano == '1971'){echo "selected=true";} ?> >1971</option>
                            <option value="1970" <?php if($ano == '1970'){echo "selected=true";} ?> >1970</option>
                            <option value="1969" <?php if($ano == '1969'){echo "selected=true";} ?> >1969</option>
                            <option value="1968" <?php if($ano == '1968'){echo "selected=true";} ?> >1968</option>
                            <option value="1967" <?php if($ano == '1967'){echo "selected=true";} ?> >1967</option>
                            <option value="1966" <?php if($ano == '1966'){echo "selected=true";} ?> >1966</option>
                            <option value="1965" <?php if($ano == '1965'){echo "selected=true";} ?> >1965</option>
                            <option value="1964" <?php if($ano == '1964'){echo "selected=true";} ?> >1964</option>
                            <option value="1963" <?php if($ano == '1963'){echo "selected=true";} ?> >1963</option>
                            <option value="1962" <?php if($ano == '1962'){echo "selected=true";} ?> >1962</option>
                            <option value="1961" <?php if($ano == '1961'){echo "selected=true";} ?> >1961</option>
                            <option value="1960" <?php if($ano == '1960'){echo "selected=true";} ?> >1960</option>
                            <option value="1959" <?php if($ano == '1959'){echo "selected=true";} ?> >1959</option>
                            <option value="1958" <?php if($ano == '1958'){echo "selected=true";} ?> >1958</option>
                            <option value="1957" <?php if($ano == '1957'){echo "selected=true";} ?> >1957</option>
                            <option value="1956" <?php if($ano == '1956'){echo "selected=true";} ?> >1956</option>
                            <option value="1955" <?php if($ano == '1955'){echo "selected=true";} ?> >1955</option>
                            <option value="1954" <?php if($ano == '1954'){echo "selected=true";} ?> >1954</option>
                            <option value="1953" <?php if($ano == '1953'){echo "selected=true";} ?> >1953</option>
                            <option value="1952" <?php if($ano == '1952'){echo "selected=true";} ?> >1952</option>
                            <option value="1951" <?php if($ano == '1951'){echo "selected=true";} ?> >1951</option>
                            <option value="1950" <?php if($ano == '1950'){echo "selected=true";} ?> >1950</option>
                            <option value="1949" <?php if($ano == '1949'){echo "selected=true";} ?> >1949</option>
                            <option value="1948" <?php if($ano == '1948'){echo "selected=true";} ?> >1948</option>
                            <option value="1947" <?php if($ano == '1947'){echo "selected=true";} ?> >1947</option>
                            <option value="1946" <?php if($ano == '1946'){echo "selected=true";} ?> >1946</option>
                            <option value="1945" <?php if($ano == '1945'){echo "selected=true";} ?> >1945</option>
                            <option value="1944" <?php if($ano == '1944'){echo "selected=true";} ?> >1944</option>
                            <option value="1943" <?php if($ano == '1943'){echo "selected=true";} ?> >1943</option>
                            <option value="1942" <?php if($ano == '1942'){echo "selected=true";} ?> >1942</option>
                            <option value="1941" <?php if($ano == '1941'){echo "selected=true";} ?> >1941</option>
                            <option value="1940" <?php if($ano == '1940'){echo "selected=true";} ?> >1940</option>
                            <option value="1939" <?php if($ano == '1939'){echo "selected=true";} ?> >1939</option>
                            <option value="1938" <?php if($ano == '1938'){echo "selected=true";} ?> >1938</option>
                            <option value="1937" <?php if($ano == '1937'){echo "selected=true";} ?> >1937</option>
                            <option value="1936" <?php if($ano == '1936'){echo "selected=true";} ?> >1936</option>
                            <option value="1935" <?php if($ano == '1935'){echo "selected=true";} ?> >1935</option>
                            <option value="1934" <?php if($ano == '1934'){echo "selected=true";} ?> >1934</option>
                            <option value="1933" <?php if($ano == '1933'){echo "selected=true";} ?> >1933</option>
                            <option value="1932" <?php if($ano == '1932'){echo "selected=true";} ?> >1932</option>
                            <option value="1931" <?php if($ano == '1931'){echo "selected=true";} ?> >1931</option>
                            <option value="1930" <?php if($ano == '1930'){echo "selected=true";} ?> >1930</option>
                            <option value="1929" <?php if($ano == '1929'){echo "selected=true";} ?> >1929</option>
                            <option value="1928" <?php if($ano == '1928'){echo "selected=true";} ?> >1928</option>
                            <option value="1927" <?php if($ano == '1927'){echo "selected=true";} ?> >1927</option>
                            <option value="1926" <?php if($ano == '1926'){echo "selected=true";} ?> >1926</option>
                            <option value="1925" <?php if($ano == '1925'){echo "selected=true";} ?> >1925</option>
                            <option value="1924" <?php if($ano == '1924'){echo "selected=true";} ?> >1924</option>
                            <option value="1923" <?php if($ano == '1923'){echo "selected=true";} ?> >1923</option>
                            <option value="1922" <?php if($ano == '1922'){echo "selected=true";} ?> >1922</option>
                            <option value="1921" <?php if($ano == '1921'){echo "selected=true";} ?> >1921</option>
                            <option value="1920" <?php if($ano == '1920'){echo "selected=true";} ?> >1920</option>
                            <option value="1919" <?php if($ano == '1919'){echo "selected=true";} ?> >1919</option>
                            <option value="1918" <?php if($ano == '1918'){echo "selected=true";} ?> >1918</option>
                            <option value="1917" <?php if($ano == '1917'){echo "selected=true";} ?> >1917</option>
                            <option value="1916" <?php if($ano == '1916'){echo "selected=true";} ?> >1916</option>
                            <option value="1915" <?php if($ano == '1915'){echo "selected=true";} ?> >1915</option>
                            <option value="1914" <?php if($ano == '1914'){echo "selected=true";} ?> >1914</option>
                            <option value="1913" <?php if($ano == '1913'){echo "selected=true";} ?> >1913</option>
                            <option value="1912" <?php if($ano == '1912'){echo "selected=true";} ?> >1912</option>
                            <option value="1911" <?php if($ano == '1911'){echo "selected=true";} ?> >1911</option>
                            <option value="1910" <?php if($ano == '1910'){echo "selected=true";} ?> >1910</option>
                            <option value="1909" <?php if($ano == '1909'){echo "selected=true";} ?> >1909</option>
                            <option value="1908" <?php if($ano == '1908'){echo "selected=true";} ?> >1908</option>
                            <option value="1907" <?php if($ano == '1907'){echo "selected=true";} ?> >1907</option>
                            <option value="1906" <?php if($ano == '1906'){echo "selected=true";} ?> >1906</option>
                            <option value="1905" <?php if($ano == '1905'){echo "selected=true";} ?> >1905</option>
                            <option value="1904" <?php if($ano == '1904'){echo "selected=true";} ?> >1904</option>
                            <option value="1903" <?php if($ano == '1903'){echo "selected=true";} ?> >1903</option>
                            <option value="1902" <?php if($ano == '1902'){echo "selected=true";} ?> >1902</option>
                            <option value="1901" <?php if($ano == '1901'){echo "selected=true";} ?> >1901</option>
                            <option value="1900" <?php if($ano == '1900'){echo "selected=true";} ?> >1900</option>
                        </select>
                    </td></tr>
                <tr><td><label>Identidade:&nbsp;&nbsp;</label></td>
                    <td>
                        <input type="text" name="identidade"
                               value="<?php echo $linha[4]; ?>"></input>
                    </td></tr>
                <tr><td><label>Órgão Emissor:&nbsp;&nbsp;</label></td>
                    <td>
                        <input type="text" name="emissor"
                               value="<?php echo $linha[5]; ?>"></input>
                    </td></tr>
                <tr><td><label>Estado Civil:&nbsp;&nbsp;</label></td>
                    <td>
                        <select name="estadoCivil">
                            <option value="Solteiro(a)" <?php if($linha[6] == "Solteiro(a)"){ echo "selected='true'";} ?> >Solteiro(a)</option>
                            <option value="Casado(a)" <?php if($linha[6] == "Casado(a)"){ echo "selected='true'";} ?> >Casado(a)</option>
                            <option value="Separado(a)" <?php if($linha[6] == "Separado(a)"){ echo "selected='true'";} ?> >Separado(a)</option>
                            <option value="Divorciado(a)" <?php if($linha[6] == "Divorciado(a)"){ echo "selected='true'";} ?> >Divorciado(a)</option>
                            <option value="Viúvo(a)" <?php if($linha[6] == "Viúvo(a)"){ echo "selected='true'";} ?> >Viúvo(a)</option>
                        </select>
                    </td></tr>
                <tr><td><label>Sexo:&nbsp;&nbsp;</label></td>
                    <td>
                        <select name="sexo">
                            <option value="Masculino" <?php if($linha[7] == "Masculino"){echo "selected='true'";} ?> >Masculino</option>
                            <option value="Feminino" <?php if($linha[7] == "Feminino"){echo "selected='true'";} ?> >Feminino</option>
                        </select>
                    </td></tr>
                <tr>
                    <td colspan="2" align="right">
                        <input type="button" value="Atualizar" onclick="cli_atualizar_pessoa();"></input>
                        <input type="button" value="Excluir" onclick="cli_excluir_pessoa();"></input>
                    </td>
                </tr>
            </table>
            <table>
                <tr>
                    <td id="telefoneResponse" colspan="2" align="center"></td>
                </tr>
                <tr>
                    <td id="listarTelefone" colspan="2" align="center">
                        <input type="button" onclick="cli_listar_telefone()" value="Telefones"</input>
                        <input type="button" onclick="carrega('listarTelefone', 'Paginas/Clientes/telefoneForm.php', 'Adicionar Telefone')" value="Adicionar novo número"</input>
                    </td>
                </tr>
            </table>
            <table>
                <tr>
                    <td id="emailResponse" colspan="2" align="center"></td>
                </tr>
                <tr>
                    <td id="listarEmail" colspan="2" align="center">
                        <input type="button" onclick="cli_listar_email()" value="Emails"</input>
                        <input type="button" onclick="carrega('listarEmail', 'Paginas/Clientes/emailForm.php', 'Adicionar Email')" value="Adicionar novo email"</input>
                    </td>
                </tr>
            </table>
            <table>
                <tr>
                    <td id="enderecoResponse" colspan="2" align="center"></td>
                </tr>
                <tr>
                    <td id="listarEndereco" colspan="2" align="center">
                        <input type="button" onclick="cli_listar_endereco()" value="Endereços"</input>
                        <input type="button" onclick="carrega('listarEndereco', 'Paginas/Clientes/enderecoForm.php', 'Adicionar Endereço')" value="Adicionar novo endereço"</input>
                    </td>
                </tr>
            </table>
        </form>
        <?php
    }
}
?>
